﻿#region

using System.ComponentModel;
using System.Windows;
using System.Windows.Data;

#endregion

namespace Radovici.SharedLibrary
{
    public class BindingHelper : Notifiable
    {
        public double Value
        {
            get { return _value; }
            set
            {
                _value = value;
                Notify("Value");
            }
        }

        public static void SetBinding(FrameworkElement target, DependencyProperty dp, INotifyPropertyChanged source,
                                      string path, BindingMode mode)
        {
            var binding = new Binding(path);
            binding.Source = source;
            binding.Mode = mode;
            target.SetBinding(dp, binding);
        }

        public static void SetBinding(FrameworkElement source, DependencyProperty sourceDp, FrameworkElement target,
                                      DependencyProperty targetDp)
        {
            var bh = new BindingHelper();
            SetBinding(bh, source, sourceDp, BindingMode.TwoWay);
            SetBinding(bh, target, targetDp);
        }

        public static void SetBinding(FrameworkElement source, FrameworkElement target, DependencyProperty dp)
        {
            var bh = new BindingHelper();
            SetBinding(bh, source, dp, BindingMode.TwoWay);
            SetBinding(bh, target, dp);
        }

        public static void SetBinding(BindingHelper bindingHelper, FrameworkElement target, DependencyProperty dp)
        {
            SetBinding(bindingHelper, target, dp, BindingMode.OneWay);
        }

        public static void SetBinding(BindingHelper bindingHelper, FrameworkElement target, DependencyProperty dp,
                                      BindingMode mode)
        {
            var binding = new Binding("Value");
            binding.Source = bindingHelper;
            binding.Mode = mode;
            target.SetBinding(dp, binding);
        }

        #region Private fields

        private double _value;

        #endregion
    }
}